<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>call_apply</title>
  </head>

  <body>
    <!-- 代码行向左或向右缩进:   Ctrl+[ 、 Ctrl+]

    复制或剪切当前行/当前选中内容:   Ctrl+C 、 Ctrl+V
    
    代码格式化:   Shift+Alt+F
    
    向上或向下移动一行:   Alt+Up 或 Alt+Down
    
    向上或向下复制一行:   Shift+Alt+Up 或 Shift+Alt+Down
    
    在当前行下方插入一行:   Ctrl+Enter
    
    在当前行上方插入一行:   Ctrl+Shift+Enter -->
    <button>adun</button>
    <button>哈哈哈</button>
  </body>
  <script>
    let arr = [5, 1, 4, 5, 6];
    console.log(Math.max(...arr));
    console.log(Math.max.call(Math, ...arr));
    console.log(Math.max.apply(Math, arr));

    function show() {
      alert(this.innerHTML);
    }

    let buttons = document.querySelectorAll("button");

    // buttons.forEach(elem => {
    //   // console.log(elem.innerHTML);

    //   elem.addEventListener("click", event => {
    //     show.call(elem);
    //   });
    // });

    for (let i = 0; i < buttons.length; i++) {
      const element = buttons[i];
      // console.log(element);
      element.addEventListener("click", event => {
        // console.log(event.target);
        show.apply(event.target);
      });
    }
  </script>
</html>
